package com.wc.codeforces.模拟.Bessie_and_MEX;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/6/23 15:53
 * @description https://codeforces.com/problemset/problem/1942/B
 */
public class Main {
    /**
     * 思路：
     * 模拟，
     * i = 1的时候, 很容易推出, 当p[1] = 0 <=> a[1] = 1,
     * 并且 p[1] != 0 <=> mex - p[1] = a[1] => 0 - p[1] = a[1] => p[1] = -a[1],
     * i > 1
     * 当前p[i]的值, 要么p[i] = mex, 要么p[i] != mex
     * p[i] = mex, 就需要寻找下一个mex = nmex
     * 难点是如何快速找下一个mex呢, 双指针法, 下一个nmex = 下一个没有被标记的点咯
     * p[i] != mex是最简单的, 因为 a[i] = mex - p[i] =>  p[i] = mex - a[i]
     * 这样所有问题都解决的
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 200010;
    static int[] a = new int[N], res = new int[N];
    // 标记
    static boolean[] f = new boolean[N];
    static int n;

    public static void main(String[] args) {
        int T = sc.nextInt();
        while (T-- > 0) {
            n = sc.nextInt();
            Arrays.fill(f, 0, n + 1, false);
            for (int i = 1; i <= n; i++) a[i] = sc.nextInt();
            if (a[1] == 1) res[1] = 0;
            else res[1] = -a[1];
            f[res[1]] = true;
            int mex = 0;
            while (f[mex]) mex++;
            int nmex = mex + 1;
            // 这里需要优化一下
            while (nmex <= n && f[nmex]) nmex++;
            for (int i = 2; i <= n; i++) {
                // p[i] = mex
                while (nmex <= n && f[nmex]) nmex++;
                if (nmex <= n && nmex - mex == a[i]) {
                    res[i] = mex;
                    mex = nmex;
                    nmex++;
                } else res[i] = mex - a[i];
                // p[i] != mex
                f[res[i]] = true;
            }
            for (int i = 1; i <= n; i++) out.print(res[i] + " ");
            out.println();
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
